package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ListView;

import com.andview.refreshview.XRefreshView;
import com.kpx.app.R;
import com.kpx.app.adapter.IncomeRecordAdapter;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.IncomeRecordBean;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.HttpDataRequest;
import com.kpx.app.http.ResObj;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.view.TitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/3/6.
 * 我的实物收入纪录
 */

public class ActivityIncomeRecord extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.lv_incomes_show)
    ListView lvIncomesShow;
    @BindView(R.id.custom_view)
    XRefreshView outView;
    private List<IncomeRecordBean> recordBeens = new ArrayList<>();
    private IncomeRecordAdapter adapter;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_income_record);
        ButterKnife.bind(this);
        UIUtils.setNormalTitle(titleview,"我的实物");
    }

    @Override
    public void initData() {
        initRefreshView();
        //商品列表的上下拉刷新操作
        outView.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
            @Override
            public void onRefresh() {
                outView.stopRefresh();
                getIncomeRecord();// 获取数据
            }

            @Override
            public void onLoadMore(boolean isSlience) {
                outView.setLoadComplete(true);
            }
        });

        adapter = new IncomeRecordAdapter(ActivityIncomeRecord.this,recordBeens, R.layout.item_income_record);
        lvIncomesShow.setAdapter(adapter);
    }

    private void getIncomeRecord() {
        new HttpDataLoader(new HttpDataApi.OnRequestCallback() {
            @Override
            public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {

            }

            @Override
            public void onRequestError(String url, int statusCode, String error) {

            }
        },IncomeRecordBean.class, HttpDataRequest.TYPE_LIST).GET("",true);
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }

    /**
     * 初始化上下拉刷新
     */
    private void initRefreshView() {
        outView.setPullLoadEnable(true);
        outView.setPinnedTime(1000);
        outView.setAutoLoadMore(true);
//		outView.setCustomHeaderView(new CustomHeader(this));
//		outView.setCustomHeaderView(new XRefreshViewHeader(this));
        outView.setMoveForHorizontal(true);
//        outView.setCustomFooterView(new CustomerFooter(this));
//		outView.setPinnedContent(true);
    }

}
